package com.wang.dao;

import com.wang.io.Resource;
import com.wang.pojo.User;
import com.wang.sqlsession.SqlSession;
import com.wang.sqlsession.SqlSessionFactory;
import com.wang.sqlsession.SqlSessionFactoryBuilder;
import org.dom4j.DocumentException;

import java.beans.PropertyVetoException;
import java.io.InputStream;
import java.util.List;

/**
 * Created by wangq on 2021/7/1.
 */
public class UserDaoImpl {

    public List<User> findAll() throws Exception {
        InputStream inputStream = Resource.getResourceAsStream("SqlMapConfig.xml");
        SqlSessionFactory sqlSessionFactory = SqlSessionFactoryBuilder.build(inputStream);
        SqlSession sqlSession = sqlSessionFactory.openSession();

        List<User> userList = sqlSession.selectList("user.selectList");
        return userList;
    }

    public User findByCondition(User user) throws Exception {
        InputStream inputStream = Resource.getResourceAsStream("SqlMapConfig.xml");
        SqlSessionFactory sqlSessionFactory = SqlSessionFactoryBuilder.build(inputStream);
        SqlSession sqlSession = sqlSessionFactory.openSession();


        User userMsg = new User();
        userMsg.setId(2);
        userMsg.setName("mike");

        User userOne = sqlSession.selectOne("user.selectOne", userMsg);
        return userOne;
    }
}
